﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace GypeInject
{
    class Program
    {
        private static void ShowHelp()
        {
            Console.WriteLine("Y U NO USING ME CORRECTLY???????");
        }

        static void Main(string[] args)
        {
            Process.EnterDebugMode();

            if (args.Length < 3)
            {
                foreach (string s in args)
                    Console.WriteLine(s);
                ShowHelp();

                Console.ReadLine();
                return;
            }
            
            try
            {
                var process = Process.GetProcessById(Int32.Parse(args[2]));
                if (args[0] == "-i")
                {
                    IntPtr address;
                    var module = Injector.Inject(process, args[1], out address);
                    Injector.CallStart(process, address);
                }
                else if (args[0] == "-e")
                {
                    Win32.ModuleEntry32 entry = new Win32.ModuleEntry32();
                    
                    Win32.EnumProcessModules(process.Id, delegate(Win32.ModuleEntry32 module)
                    {
                        if (module.ModulePath == args[1])
                        {
                            entry = module;
                            return true;
                        }
 
                        return false;
                    });

                    Injector.UnloadDll(process, entry);
                }
                else
                    ShowHelp();
            }
            catch (Exception)
            {
                ShowHelp();
                return;
            }

            return;
        }
    }
}
